package com.ldc.wandroid.viewmodel;

import com.ldc.wandroid.contracts.MeContract;
import com.ldc.common.mvp.BasePresenter;
import com.ldc.common.model.BaseModel;
import com.ldc.wandroid.model.IntegralModel;
import com.ldc.common.net.Api2Request;
import com.ldc.common.utils.RxThreadUts;
import com.ldc.wandroid.server.ApiServer;

import io.reactivex.Observer;
import io.reactivex.disposables.Disposable;

public class MePresenter extends BasePresenter<MeContract.V> implements MeContract.P {
    private final ApiServer apiServer;

    public MePresenter() {
        apiServer = Api2Request.getInstance().createServer(ApiServer.class);
    }



    @Override
    public void get_integral_req() {
        apiServer.get_integral()
                .compose(RxThreadUts.observableTransformer())
                .subscribe(new Observer<BaseModel<IntegralModel>>() {
                    Disposable disposable;

                    @Override
                    public void onSubscribe(Disposable d) {
                        disposable = d;
                    }

                    @Override
                    public void onNext(BaseModel<IntegralModel> integralModelBaseModel) {
                        getView().get_integral_resp(integralModelBaseModel);

                    }

                    @Override
                    public void onError(Throwable e) {
                        release_disposable(disposable);
                    }

                    @Override
                    public void onComplete() {
                        release_disposable(disposable);

                    }
                });
    }
}
